package com.dxyxx.framework;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.type.JavaType;

import zrc.widget.SimpleFooter;
import zrc.widget.SimpleHeader;
import zrc.widget.ZrcListView;
import zrc.widget.ZrcListView.OnStartListener;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

import com.android.customized.PullDownView;
import com.dxyxx.R;
import com.dxyxx.dialog.AgainPlayer;
import com.dxyxx.framework.CAS.CallBack;
import com.dxyxx.framework.OrderListActivity.BarcodeClickListener;
import com.dxyxx.pojo.GroupOrder;
import com.dxyxx.pojo.GroupOrderRecords;
import com.dxyxx.pojo.Product;
import com.dxyxx.pojo.ResponseResult;
import com.http.HttpUtil;
import com.loopj.android.http.AsyncHttpResponseHandler;

public class GroupOrderFragment extends BaseFragment {

	private final static String INDEX = "index";
	private final static String TIME = "time";
	private final static String IMAGE = "image";
	private final static String UUID = "uuid";
	private final static String ID = "id";
	private final static String UUIDStr = "UUIDStr";
	private final static String DETAIL = "detail";
	private final static String MONEY = "money";
	private final static String DATE = "date";
	final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	final SimpleDateFormat dateSdf = new SimpleDateFormat("MM月dd日");

	private ArrayList<String> msgs;
	private int pageId = -1;
	private MyAdapter2 adapter;

	private String[][] names;

	private Handler handler;
	/** 总页数. */
	private int PageCount;
	/** 当前页码. */
	private int PageCurrent;
	/** 被选中的. */
	private int gridID = -1;
	/** 每页显示的数量，Adapter保持一致. */
	private static final float PAGE_SIZE = 12.0f;
	/** GridView. */
	private GridView gridView;
	/** 自定义的左右滑动. */
	private ViewPager vp;
	/** 页码条布局. */
	private LinearLayout layoutBottom;

	/** 页码条. */
	private ImageView imgCur;
	// common private
	// private PullDownView commonView;
	private ListView commonLv;
	private PullDownView privateView;
	private ListView privateLv;
	private PullDownView otherView;
	private ListView otherLv;

	private List<View> list;
	private boolean firstInitFinished = false;
	// 分享四个 字段。。
	private String text;//分享文本
	String titleUrl;//分享的题目
	String imageUrl;//分享的图片
	String url;//分享的网址

	@Override
	public void onResume() {
		try {
			// 第一次加载，那么 肯定还没有finished。那么firstInitFinished=false。那么不会执行refresh(0)
			// 第二次加载，因为 上一次加载结束之后。firstInitFinished=true，所以执行刷新操作
			if (firstInitFinished) {
				refresh(0);
				refresh(1);
			} else {
				//  走到这里，firstInitFinished 结束
				firstInitFinished = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.onResume();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View view = inflater.inflate(R.layout.activity_orderlist, container, false);
		view.findViewById(R.id.titlebar).setVisibility(View.GONE);
		initViews(view);
		setGrid();

		return view;
		//

	}

	/**
	 * 初始化
	 */
	private TextView commonText;
	private TextView privateText;
	private View commonTab;
	private View privateTab;
	private TextView otherText;
	private View otherTab;

	private void initViews(View view) {

		commonData = new ArrayList<Map<String, String>>();
		privateData = new ArrayList<Map<String, String>>();

		// /-----------init data

		// // init data finished
		list = new ArrayList<View>();
		vp = (ViewPager) view.findViewById(R.id.vp_message_launcher_layout);
		vp.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				setCurPage(arg0);
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});
		commonText = (TextView) view.findViewById(R.id.commonText);
		commonText.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (vp.getCurrentItem() != 0) {

					vp.setCurrentItem(0);
					System.out.println(vp.getCurrentItem());
				}
			}
		});
		privateText = (TextView) view.findViewById(R.id.privateText);
		privateText.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (vp.getCurrentItem() != 1) {

					vp.setCurrentItem(1);
				}
			}
		});
		otherText = (TextView) view.findViewById(R.id.otherText);
		otherText.setText("已提货");
		otherText.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (vp.getCurrentItem() != 2) {

					vp.setCurrentItem(2);
				}
			}
		});
		commonTab = view.findViewById(R.id.commonTab);
		privateTab = view.findViewById(R.id.privateTab);
		otherTab = view.findViewById(R.id.otherTab);

		layoutBottom = (LinearLayout) view.findViewById(R.id.layout_scr_bottom);

	}

	/**
	 * 添加GridView
	 */
	private ZrcListView listView;
	private ViewGroup viewGroupUndone;
	private ViewGroup viewGroupDone;
	private ViewGroup viewGroupCancel;
	private LayoutInflater mInflater;

	/**
	 * 添加ListView
	 * 
	 */
	private ZrcListView[] listViews;
	private ViewGroup[] waitViewGroups;
	private MessageAdapter[] messageAdapters;
	private List<Map<String, String>>[] datas;

	private void setGrid() {

		// 初始化数据
		listViews = new ZrcListView[3];
		waitViewGroups = new ViewGroup[3];
		messageAdapters = new MessageAdapter[3];
		datas = new List[3];
		// 在这里添加视图。多个自定义的View
		mInflater = LayoutInflater.from(getActivity());
		for (int i = 0; i < 3; i++) {
			waitViewGroups[i] = (ViewGroup) mInflater.inflate(R.layout.fragment_wait, null);
			listViews[i] = (ZrcListView) mInflater.inflate(R.layout.component_order_listview, null);
			listViews[i].setDivider(getResources().getDrawable(R.color.common_list_devider_color));
			listViews[i].setDividerHeight(2);
			setStyle(listViews[i]);
			datas[i] = new ArrayList<Map<String, String>>();
			messageAdapters[i] = new MessageAdapter(getActivity(), i, datas[i]);
		}
		String undoneOrderUrl = "gorder/get?propId=1&currentPage=1&pageSize=" + COUNT;
		HttpUtil.get(undoneOrderUrl, new DownloadOrderHandler(listViews[0], waitViewGroups[0], messageAdapters[0], 0, false));
		String urlString1 = "gorder/get?propId=2&currentPage=1&pageSize=" + COUNT;
		HttpUtil.get(urlString1, new DownloadOrderHandler(listViews[1], waitViewGroups[1], messageAdapters[1], 1, false));
		String urlString2 = "gorder/get?propId=3&currentPage=1&pageSize=" + COUNT;
		HttpUtil.get(urlString2, new DownloadOrderHandler(listViews[2], waitViewGroups[2], messageAdapters[2], 2, false));

		for (int i = 0; i < 3; i++) {
			final int index = i;
			// 下拉刷新事件回调（可选）
			listViews[index].setOnRefreshStartListener(new OnStartListener() {
				@Override
				public void onStart() {
					refresh(index);
				}
			});

			// 加载更多事件回调（可选）
			listViews[index].setOnLoadMoreStartListener(new OnStartListener() {
				@Override
				public void onStart() {
					loadMore(index);
				}
			});

		}

		for (ViewGroup temp : waitViewGroups) {
			list.add(temp);
		}
		vp.setAdapter(new MyAdapter());

	}

	class MyAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == arg1;
		}

		@Override
		public int getItemPosition(Object object) {
			return super.getItemPosition(object);
		}

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			((ViewPager) arg0).removeView(list.get(arg1));
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			((ViewPager) arg0).addView(list.get(arg1));
			return list.get(arg1);
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
		}

		@Override
		public void finishUpdate(View arg0) {
		}

	}

	/**
	 * GridView的监听事件
	 */
	public OnItemClickListener gridListener = new OnItemClickListener() {

		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			/*
			 * PageCurrent = curPage.getCurScreen(); gridID = arg2 + PageCurrent
			 * * 12;
			 * 
			 * if (((GridView) arg0).getTag() != null) { ((View) ((GridView)
			 * arg0).getTag()).setBackgroundResource(R.drawable.bg_grid_item); }
			 * ((GridView) arg0).setTag(arg1);
			 * arg1.setBackgroundResource(R.drawable.bg_grid_item_false);
			 */
		}
	};

	/**
	 * 更新当前页码
	 */
	public void setCurPage(int page) {
		switch (page) {
		case 0:
			commonText.setTextColor(0xffFFD101);
			privateText.setTextColor(0xffcccccc);
			otherText.setTextColor(0xffcccccc);
			commonTab.setBackgroundColor(getResources().getColor(R.color.theme_color));
			privateTab.setBackgroundColor(getResources().getColor(R.color.transparent));
			otherTab.setBackgroundColor(getResources().getColor(R.color.transparent));
			break;
		case 1:
			privateText.setTextColor(0xffFFD101);
			commonText.setTextColor(0xffcccccc);
			otherText.setTextColor(0xffcccccc);
			privateTab.setBackgroundColor(getResources().getColor(R.color.theme_color));
			commonTab.setBackgroundColor(getResources().getColor(R.color.transparent));
			otherTab.setBackgroundColor(getResources().getColor(R.color.transparent));
			break;
		case 2:
			otherText.setTextColor(0xffFFD101);
			commonText.setTextColor(0xffcccccc);
			privateText.setTextColor(0xffcccccc);
			otherTab.setBackgroundColor(getResources().getColor(R.color.theme_color));
			commonTab.setBackgroundColor(getResources().getColor(R.color.transparent));
			privateTab.setBackgroundColor(getResources().getColor(R.color.transparent));
			break;
		default:
			break;
		}
	}

	private List<Map<String, String>> commonData;
	private List<Map<String, String>> privateData;

	private class MyAdapter2 extends BaseAdapter {
		@Override
		public int getCount() {
			return msgs == null ? 0 : msgs.size();
		}

		@Override
		public Object getItem(int position) {
			return msgs.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			TextView textView;
			if (convertView == null) {
				textView = (TextView) getActivity().getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null);
			} else {
				textView = (TextView) convertView;
			}
			textView.setText(msgs.get(position));
			return textView;
		}
	}

	// adpter 

	// / 写一个通用的类。
	class DownloadOrderHandler extends AsyncHttpResponseHandler {
		// 需要传进来 ListView 跟waitViewGrop
		private zrc.widget.ZrcListView listView;
		private ViewGroup waitViewGroup;
		private MessageAdapter messageAdapter;
		// private List<Map<String, String>> data;
		private int index;
		private boolean isRefresh;

		public DownloadOrderHandler(zrc.widget.ZrcListView listView, ViewGroup waitViewGroup, MessageAdapter messageAdapter, int index, boolean isRefresh) {
			this.listView = listView;
			this.waitViewGroup = waitViewGroup;
			// this.data = data;
			this.index = index;
			this.messageAdapter = messageAdapter;
			this.isRefresh = isRefresh;
		}

		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
			listView.setRefreshSuccess("加载失败");
		}

		@Override
		public void onSuccess(int arg0, Header[] arg1, byte[] responseStr) {
			try {
				JavaType javaType = getObjectMapper().getTypeFactory().constructParametricType(ResponseResult.class, GroupOrderRecords.class);
				ResponseResult<GroupOrderRecords> result = getObjectMapper().readValue(new String(responseStr), javaType);

				List<Map<String, String>> downloadData = new ArrayList<Map<String, String>>();
				//设置 data
				downloadData = setOrderData(index, result);

				// 设置data ends

				datas[index].addAll(downloadData);
				if (!isRefresh) {

					listView.setAdapter(messageAdapter);
					// listView.refresh(); // 主动下拉刷新

					waitViewGroup.addView(listView);
				} else {
					// 刷新

					messageAdapter.data = datas[index];
					messageAdapter.notifyDataSetChanged();
					listView.setRefreshSuccess("加载成功"); // 通知加载成功

				}
			} catch (JsonParseException e) {
				e.printStackTrace();
			} catch (JsonMappingException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
	}

	// / 写一个通用的类。
	class DownloadMoreOrderHandler extends AsyncHttpResponseHandler {
		// 需要传进来 ListView 跟waitViewGrop
		private zrc.widget.ZrcListView listView;
		private ViewGroup waitViewGroup;
		private MessageAdapter messageAdapter;
		private List<Map<String, String>> data;
		private int index;

		public DownloadMoreOrderHandler(zrc.widget.ZrcListView listView, ViewGroup waitViewGroup, MessageAdapter messageAdapter, List<Map<String, String>> data, int index) {
			this.listView = listView;
			this.waitViewGroup = waitViewGroup;
			this.data = data;
			this.messageAdapter = messageAdapter;
			this.index = index;

		}

		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
			AgainPlayer.makeCall(getActivity(), "网络异常");
		}

		@Override
		public void onSuccess(int arg0, Header[] arg1, byte[] responseStr) {
			try {
				JavaType javaType = getObjectMapper().getTypeFactory().constructParametricType(ResponseResult.class, GroupOrderRecords.class);
				ResponseResult<GroupOrderRecords> result = getObjectMapper().readValue(new String(responseStr), javaType);

				List<Map<String, String>> downloaddata = new ArrayList<Map<String, String>>();
				//设置 data
				downloaddata = setOrderData(index, result);

				if (downloaddata.size() == 0) {
					listView.stopLoadMore();
				} else {
					data.addAll(downloaddata);
					messageAdapter.notifyDataSetChanged();
					listView.setLoadMoreSuccess(); // 通知加载成功
				}
			} catch (JsonParseException e) {
				e.printStackTrace();
			} catch (JsonMappingException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
	}

	/**
	 * 
	 * @param shareUrl
	 * @param text
	 */
	private void showShare(String text, String titleUrl, String imageUrl, String url) {
		//ShareSDK.initSDK(getActivity());
		OnekeyShare oks = new OnekeyShare();
		//关闭sso授权
		oks.disableSSOWhenAuthorize();

		// 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
		//oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
		// title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
		oks.setTitle("开团" + getString(R.string.share));
		// titleUrl是标题的网络链接，仅在人人网和QQ空间使用
		//oks.setTitleUrl("http://dxyxx.com");
		oks.setTitleUrl(titleUrl);
		// text是分享文本，所有平台都需要这个字段
		//oks.setText("超级大芒果，快来抢啊。http://pay.dxyxx.com:8080/chinesejie/html/wcpay/wcPay.html?id=1");
		oks.setText(text);
		// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
		// oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片 没有这个图片，微信分享会失败。
		//oks.setImageUrl("http://pay.dxyxx.com:4869/aebc22ab8730baf17ae7a9177e5cdd38?p=0");
		oks.setImageUrl(imageUrl);
		// url仅在微信（包括好友和朋友圈）中使用
		//oks.setUrl("http://pay.dxyxx.com:8080/chinesejie/html/wcpay/wcPay.html?id=1");
		oks.setUrl(url);
		// comment是我对这条分享的评论，仅在人人网和QQ空间使用
		oks.setComment("这家店还不错！");
		// site是分享此内容的网站名称，仅在QQ空间使用
		oks.setSite(getString(R.string.app_name));
		// siteUrl是分享此内容的网站地址，仅在QQ空间使用
		oks.setSiteUrl("http://rs88881234.com");

		// 启动分享GUI
		oks.show(getActivity());
	}

	//adapter...
	// 异步下载信息
	private ViewHolder holder = null; // 如果缓存convertView为空，则需要创建View

	public class MessageAdapter extends BaseAdapter {
		private List<Map<String, String>> data;
		private int messageType;

		public MessageAdapter(Context context, int messageType, List<Map<String, String>> data) {
			this.mInflater = LayoutInflater.from(context);
			this.data = data;
			this.messageType = messageType;
		}

		// ViewHolder静态类
		private LayoutInflater mInflater = null;

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Map<String, String> map = this.data.get(position);

			holder = null;

			//int type = getItemViewType(position);
			if (convertView == null) {// 如果缓存convertView为空，则需要创建View
				holder = new ViewHolder();
				// 根据自定义的Item布局加载布局
				switch (messageType) {
				case 0:
					convertView = mInflater.inflate(R.layout.item_orderlist_undone, null);
					holder.payButton = (Button) convertView.findViewById(R.id.payButton);
					break;
				case 1:
					convertView = mInflater.inflate(R.layout.item_orderlist_done, null);
					holder.shareButton = (Button) convertView.findViewById(R.id.b_shareGroup);
					holder.bufferCodeButton = (Button) convertView.findViewById(R.id.bufferCode);
					break;
				case 2:
					convertView = mInflater.inflate(R.layout.item_orderlist_buffered, null);
					holder.commentButton = (TextView) convertView.findViewById(R.id.commentButton);
					break;

				default:
					break;
				}
				holder.moneyText = (TextView) convertView.findViewById(R.id.orderMoney);
				holder.dateText = (TextView) convertView.findViewById(R.id.orderDate);
				holder.timeText = (TextView) convertView.findViewById(R.id.orderTime);
				holder.uuidText = (TextView) convertView.findViewById(R.id.orderId);
				holder.detailText = (TextView) convertView.findViewById(R.id.orderDetail);
				holder.thumbImage = (ImageView) convertView.findViewById(R.id.orderThumb);
				convertView.setTag(holder);
			}
			holder = (ViewHolder) convertView.getTag();
			if (holder.shareButton != null) {
				holder.shareButton.setVisibility(View.GONE);
			}
			holder.moneyText.setText(map.get(MONEY));
			holder.dateText.setText(map.get(DATE));
			holder.timeText.setText("下单时间：" + map.get(TIME).substring(11));
			holder.uuidText.setText("订单编号：" + map.get(UUID));
			holder.detailText.setText(map.get(DETAIL));
			imageLoader.displayImage(map.get(IMAGE), holder.thumbImage, squareOptions, animateFirstListener);
			if (holder.payButton != null) {
				holder.payButton.setOnClickListener(new PayButtonClickListener(map));
			}
			if (holder.commentButton != null) {
				holder.commentButton.setOnClickListener(new CommentButtonClickListener(map));
			}
			if (holder.bufferCodeButton != null) {// 团号分享
				holder.bufferCodeButton.setText("团号分享");
				holder.bufferCodeButton.setBackgroundColor(0x881AA68C);
				holder.bufferCodeButton.setOnClickListener(new ShareClickLsitener(map.get(IMAGE), map.get("groupinstanceId")));
			}

			convertView.setOnClickListener(new ItemClickListener(map));

			return convertView;
		}

		@Override
		public int getCount() {
			return this.data.size();
		}

		@Override
		public Object getItem(int position) {
			return position;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}
	}

	class ShareClickLsitener implements OnClickListener {

		private String groupId;//分享文本
		private String iUrl;//分享的题目

		public ShareClickLsitener(String imageUrl, String groupId) {
			this.iUrl = imageUrl;
			this.groupId = groupId;
		}

		@Override
		public void onClick(View arg0) {
			String tmpURL = "https://rs88881234.com/chinesejie/html/help/group/GroupHelp.html?id=" + groupId;
			text = "我在大象与猩猩开团了，邀您一起 " + tmpURL;//分享文本
			titleUrl = tmpURL;//分享的题目
			imageUrl = this.iUrl;//分享的图片
			url = tmpURL;//分享的网址
			showShare(text, titleUrl, imageUrl, url);
		}
	};

	class CommentButtonClickListener implements OnClickListener {
		private Map<String, String> map;

		public CommentButtonClickListener(Map<String, String> map) {
			this.map = map;
		}

		@Override
		public void onClick(View arg0) {
			dumpId = map.get("id");
			dumpUuid = map.get(UUID);
			CAS call = new CAS(getActivity(), RequestCode.OrderComment, new CallBack() {
				@Override
				public void method() {
					Intent intent = new Intent(getActivity(), OrderCommentActivity.class);
					// 用Bundle携带数据
					//传三个值 过去。
					Bundle bundle = new Bundle();
					bundle.putString("id", dumpId);
					bundle.putString("uuid", dumpUuid);
					if (intent != null) {
						intent.putExtras(bundle);
						startActivity(intent);
					}
				}
			});
			call.call();

		}
	}

	class ItemClickListener implements OnClickListener {
		private Map<String, String> map;

		public ItemClickListener(Map<String, String> map) {
			this.map = map;
		}

		@Override
		public void onClick(View arg0) {
			Intent intent = null;
			Bundle bundle = new Bundle();
			switch (Integer.parseInt(map.get(INDEX))) {
			case 0:
				intent = new Intent(getActivity(), OrderUndoneActivity.class);
				//传三个值 过去。
				bundle.putString("id", map.get("id"));
				bundle.putString("uuid", map.get(UUID));
				intent.putExtras(bundle);
				startActivityForResult(intent, RequestCode.OrderUndone);
				break;

			case 1:
				intent = new Intent(getActivity(), OrderDoneActivity.class);
				// 用Bundle携带数据
				//传三个值 过去。
				bundle.putString("id", map.get("id"));
				bundle.putString("uuid", map.get(UUID));
				if (intent != null) {
					intent.putExtras(bundle);
					startActivity(intent);
				}
				break;

			default:
				break;
			}

		}
	}

	class PayButtonClickListener implements OnClickListener {
		private Map<String, String> map;

		public PayButtonClickListener(Map<String, String> map) {
			this.map = map;
		}

		@Override
		public void onClick(View arg0) {
			//tenPay(map.get(UUID).split("：")[1]);
		}
	}

	static class ViewHolder {
		public TextView detailText;
		public TextView timeText;
		public TextView moneyText;
		public TextView dateText;
		public TextView uuidText;
		public ImageView thumbImage;
		public Button payButton;
		public Button shareButton;
		public Button bufferCodeButton;
		public TextView commentButton;
	}

	private void refresh(int index) {

		String urlString = "gorder/get?propId=1&currentPage=1&pageSize=" + COUNT;
		datas[index] = new ArrayList<Map<String, String>>();

		switch (index) {
		case 0:
			urlString = "gorder/get?propId=1&currentPage=1&pageSize=" + COUNT;
			break;
		case 1:
			urlString = "gorder/get?propId=2&currentPage=1&pageSize=" + COUNT;
			break;
		case 2:
			urlString = "gorder/get?propId=3&currentPage=1&pageSize=" + COUNT;
			break;

		default:

			break;
		}
		HttpUtil.get(urlString, new DownloadOrderHandler(listViews[index], waitViewGroups[index], messageAdapters[index], index, true));

		// adapter.notifyDataSetChanged();
		// listView1.setRefreshSuccess("加载成功"); // 通知加载成功
		// listView1.startLoadMore(); // 开启LoadingMore功能

	}

	private int[] currentPage = { 1, 1, 1 }; // 当前加载页数

	// **设置listview 头部底部的样式
	private void setStyle(ZrcListView listView) {
		// 设置下拉刷新的样式（可选，但如果没有Header则无法下拉刷新）
		SimpleHeader header = new SimpleHeader(getActivity());
		header.setTextColor(0xff0066aa);
		header.setCircleColor(0xff33bbee);
		listView.setHeadable(header);

		// 设置加载更多的样式（可选）
		SimpleFooter footer = new SimpleFooter(getActivity());
		footer.setCircleColor(0xff33bbee);
		listView.setFootable(footer);

		// 设置列表项出现动画（可选）
		listView.setItemAnimForTopIn(R.anim.topitem_in);
		listView.setItemAnimForBottomIn(R.anim.bottomitem_in);

		// 开启 加载更多多 的功能
		listView.startLoadMore();
	}

	private void loadMore(int index) {
		currentPage[index] = currentPage[index] + 1;

		String urlString = "gorder/get?propId=1&currentPage=" + currentPage[index] + "&pageSize=" + COUNT;

		switch (index) {
		case 0:
			urlString = "gorder/get?propId=1&currentPage=" + currentPage[index] + "&pageSize=" + COUNT;
			break;
		case 1:
			urlString = "gorder/get?propId=2&currentPage=" + currentPage[index] + "&pageSize=" + COUNT;
			break;
		case 2:
			urlString = "gorder/get?propId=3&currentPage=" + currentPage[index] + "&pageSize=" + COUNT;
			break;

		default:

			break;
		}

		HttpUtil.get(urlString, new DownloadMoreOrderHandler(listViews[index], waitViewGroups[index], messageAdapters[index], datas[index], index));

		// adapter.notifyDataSetChanged();
		// listView1.setLoadMoreSuccess("");

		// listView1.stopLoadMore();

	}

	private List<Map<String, String>> setOrderData(int index, ResponseResult<GroupOrderRecords> result) {
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for (GroupOrder order : result.getObject().getRecordList()) {
			Map<String, String> map = new HashMap<String, String>();
			map.put(INDEX, index + "");
			map.put(TIME, sdf.format(order.getPostTime()));
			map.put(DATE, dateSdf.format(order.getPostTime()));
			map.put(UUIDStr, "订单编号：" + order.getUuid());
			map.put(UUID, order.getUuid());
			if (order.getGroupInstance() != null) {//未付款没有团号
				map.put("groupinstanceId", order.getGroupInstance().getId() + "");
			}
			map.put(MONEY, "￥" + order.getMoney());
			map.put("id", order.getId() + "");

			StringBuilder sb = new StringBuilder();
			int i = 0;
			//			for (OrderDetail od : order.getOrderDetails()) {
			//				Product product = od.getProduct();
			//
			//				if (product != null) {
			//					if (i == 0) {
			//						map.put(IMAGE, baseImageURL + product.getThumbId() + "?p=0");
			//					}
			//					sb.append(product.getDescription() + "*" + od.getAmount() + " ");
			//				}
			//			}
			Product product = order.getGroup().getProduct();
			sb.append(product.getDescription() + " * 1");
			map.put(DETAIL, sb.toString());
			map.put(IMAGE, baseImageURL + product.getThumbId() + "?p=0");
			list.add(map);
		}
		return list;

	}

	private String dumpId;
	private String dumpUuid;

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (data != null) {
			boolean result = data.getExtras().getBoolean("result");
			switch (requestCode) {

			case RequestCode.OrderComment:
				// 使用cas 启动。
				Intent intent = new Intent(getActivity(), OrderCommentActivity.class);
				// 用Bundle携带数据
				//传三个值 过去。
				Bundle bundle = new Bundle();
				bundle.putString("id", dumpId);
				bundle.putString("uuid", dumpUuid);
				if (intent != null) {
					intent.putExtras(bundle);
					startActivity(intent);
				}
				break;

			}
		}
	}
}